package com.hw.one.dam2.dao;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.Map;

/**
 * 天气 Dao
 * 
 * @author admin
 *
 */
@Repository(value = "weatherDao")
public class WeatherDao implements IWeatherDao {

	// 在Spring中注册的 mongoDB Template
	@Autowired
	private MongoTemplate mongoTemplateCityWeather;

	@Override
	public Object findLast7DayWeatherForecast(String cityCode, String collectionName) {
		// 查询条件 增加时间查询条件
		Criteria criteria = Criteria.where("regionCode").is(cityCode);
		// 创建查询对象
		Query query = new Query(criteria);
		return mongoTemplateCityWeather.findOne(query, Object.class, collectionName);
	}

	@Override
	public Object findCityLiveWeatherByRegionCode(String cityCode) {
		// 查询条件 增加时间查询条件
		Criteria criteria = Criteria.where("regionCode").is(cityCode);
		// 创建查询对象
		Query query = new Query(criteria);
		return mongoTemplateCityWeather.findOne(query, Object.class, "air_envi_weather_Live");
	}
}
